package org.example.dao.impl;

import org.example.dao.EmpDao;
import org.example.pojo.Emp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * ClassName: EmpDaoImpl
 * Package: org.example.dao.impl
 * Description:
 *
 * @Author wanghao
 * @Create 2024-07-09 9:44
 * @Version 1.0
 */
@Repository
public class EmpDaoImpl implements EmpDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void updateEmpSalary(Integer empId, Integer salary) {
        String sql = "update t_emp set salary = ? where emp_id = ?";
        jdbcTemplate.update(sql, salary, empId);
    }

    @Override
    public void updateEmpDeptNo(Integer empId, String deptNo) {
        String sql = "update t_emp set deptNo = ? where emp_id = ?";
        jdbcTemplate.update(sql, deptNo, empId);
    }

    @Override
    public Emp getEmpByEmpId(Integer empId) {
        String sql = "select * from t_emp where emp_id = ?";
        Emp emp = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Emp.class), empId);
        return emp;
    }
}
